<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@include file="../../common/mastertop.jsp"%>
<p class="page-title">
	<i class="locale-icon"></i> <span>当前位置 : </span> <span
		class="cur-page-title">基础档案</span> <span>· 供应商档案</span>
</p>

<div class="form-inline clearfix form-label-120" id="seachform">
	<input type="hidden" name="catId" /> <input type="hidden"
		name="catLevel" />
	<div class="filter-warp rect-fff clearfix">
		<div class="form-group col-xs-6 col-lg-4">
			<span class="form-label">供应商编码/名称</span> <input type="text"
				class="form-control form-control-260" name="factoryCodeOrName" id ="factoryCodeOrName"
				value="${model.jobName}">
		</div>

		<div class="form-group col-xs-6 col-lg-4">
			<span class="form-label">
			<select  name="timeFlag"  id="timeFlag"  class="form-control">
				 <option value="1" selected="selected">创建时间</option>
				 <option value="2">修改时间</option>
			</select>
			</span>
			<div class="datapicker-gloup">
				<div class="datapicker-box form-control-125 pull-left">
					<i class="runmi-icon datetimepicker-icon"></i> <input type="text"
						class="form-control" id="start-date" name="startTime" id="d17"
						value="${model.startTime}">
				</div>
				<span class="time-line pull-left">-</span>
				<div class="datapicker-box form-control-125 pull-left">
					<i class="runmi-icon datetimepicker-icon"></i> <input type="text"
						class="form-control" id="end-date" name="endTime" id="d18"
						value="${model.endTime}">
				</div>
			</div>
		</div>
		
		<div class="form-group col-xs-6 col-lg-4">
			<span class="form-label">供应商简称</span> <input type="text"
				class="form-control form-control-260" name="factoryShortName" id ="factoryShortName"
				value="${model.jobName}">
		</div>
		
		<div class="form-group col-xs-6 col-lg-4">
			<span class="form-label">启用状态</span>
			
			<select  name="status"  id="status"  class="form-control form-control-260">
				   		<option value="" selected="selected">全部</option>
						<option value="1" >启用</option>	
						<option value="2" >停用</option>				        
			</select>
		</div>
		
		<div class="form-group col-xs-6 col-lg-4">
			<span class="form-label">备注</span> <input type="text"
				class="form-control form-control-260" name="remark" id ="remark"
				value="${model.jobName}">
		</div>

		<div class="col-xs-12 text-center">
			<button type="button" class="btn runmi-primary buttonrole"
				onclick="edit('')" name="btnadd">新&nbsp;增</button>
			<button type="button" class="btn runmi-primary search-btn"
				onclick="seach()">查询</button>
		</div>
	</div>
	<div class="rect-fff table-warp"  id="content">
	<div class="table-scroll">
		<table id="datatable" class="table-min-2800">
		<tr>
			<th width="110">操作</th>
			<th>供应商编码</th>
			<th>供应商名称</th>
			<th>供应商简称</th>
			<th>启用状态</th>
			<th>联系人</th>
			<th>联系方式</th>
			<th>地址</th>
			<th>备注</th>
			<th>创建人</th>
			<th>创建时间</th>
			<th>修改人</th>
			<th>修改时间</th>
		</tr>
		</table>
		</div>
	</div>


</div>

<script type="text/javascript">
	function getAjaxPageData(data){	
		layer.load(1, {
			shade : [ 0.5, '#fff' ]
		});
		var postData=data;
		postData= postData + "&factoryCodeOrName=" + encodeURIComponent($("#factoryCodeOrName").val());
		postData= postData + "&timeFlag=" + $("#timeFlag").val();
		postData= postData + "&startTime=" + encodeURIComponent($("#start-date").val());
		postData= postData + "&endTime=" + encodeURIComponent($("#end-date").val());
		postData= postData + "&factoryShortName=" + encodeURIComponent($("#factoryShortName").val());
		postData= postData + "&status=" + $("#status").val();
		postData= postData + "&remark=" + encodeURIComponent($("#remark").val());
		$.ajax({
			type : "POST",
			url : "queryFactoryInfo"+ "?timeStamp=" + new Date().getTime(),
			data : postData,
			contentType : "application/x-www-form-urlencoded;charset=UTF-8",
			error : function(resultdata) {
				layer.closeAll();
			},
			success : function(resultdata) {
				layer.closeAll();
				$("#datatable").hide();
				$("#content").html(resultdata);
			}
		});
	}
	$(function(){
		seach();
	});
	function seach() {
		$("#cpage").val(1);
		oksubmit();
		
	}
	function oksubmit() {
		//$("#btnOk").attr("disabled", "disabled");
		//var objform = document.getElementById('seachform');
		//objform.submit();
		var page=$("#cpage").val();
		if(page==undefined){
			page=1;
		}
		var data="&cpage=" + page;
		getAjaxPageData(data);
	}
	function del(id) {
		layer.confirm('确认要删除此供应商吗', {
			btn : [ '确认', '取消' ]
		//按钮
		}, function() {
			sendOpTo(id);
		}, function() {

		});
	}
	function sendOpTo(id) {
		layer.load(1, {
			shade : [ 0.5, '#fff' ]
		});
		var postData = "factoryId=" + id;
		$.ajax({
			type : "POST",
			url : "deleteFactoryInfo",
			data : postData,
			contentType : "application/x-www-form-urlencoded;charset=UTF-8",
			async : true, // 同步  true 异步。默认是异步
			dataType : 'json',
			error : function(resultdata) {
				layer.closeAll();
			},
			success : function(resultdata) {
				layer.closeAll();
				if (resultdata.returnCode == "0000") {
					layer.alert('操作成功', {
						icon : 1
					}, function() {
						layer.closeAll();
						oksubmit();
					});
				} else {
					layer.alert(resultdata.returnMessage);
				}
			}
		});
	}
	
	function confirm(id,type){
		if(type==1){
			layer.confirm('确认要停用此供应商吗', {
				  btn: ['确认','取消'] //按钮
				}, function(){
					swatchOpTo(id,type);
				}, function(){
				  
				});	
		}else{
			swatchOpTo(id,type);
		}

	}
	function swatchOpTo(id,type){
		layer.load(1, {shade: [0.5,'#fff']});
		var postData="factoryId=" + id + "&opType=" + type;
		 $.ajax({
	            type: "POST",
	            url: "switchFactoryInfo",
	            data: postData,
	            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	            async: true, // 同步  true 异步。默认是异步
	            dataType: 'json',
	            error: function(resultdata) {
	            	layer.closeAll();
	            },
	            success: function(resultdata) {
	            	layer.closeAll();
	                if(resultdata.returnCode=="0000"){               	
	                	layer.alert('操作成功',{icon: 1}, function(){
	                		layer.closeAll();
	                	 	 oksubmit();
	                	});
	                }else{
	                	layer.alert(resultdata.returnMessage);
	                }
	            }
	        });
	}
	

	function editReturn() {
		layer.closeAll();
		oksubmit();
	}
	function closeAll() {
		layer.closeAll();
	}
	function edit(id) {
		var domainUrl = "edit?factoryId=" + id;
		layer.open({
			type : 2,
			title : '供应商',
			area : [ '650px', '600px' ],
			content : domainUrl
		//iframe的url
		});
	}
</script>

<script>
    $('#start-date').datetimepicker({
        language:  'zh-CN',
        autoclose : true,
        minView : 2,
        format : 'yyyy/mm/dd',
        todayBtn:  1,
        pickerPosition:'bottom-left'//日期插件弹出的位置
    });
    $('#end-date').datetimepicker({
        language:  'zh-CN',
        autoclose : true,
        minView : 2,
        todayBtn:  1,
        format : 'yyyy/mm/dd',
        pickerPosition:'bottom-left'//日期插件弹出的位置
    });
</script>
<%@include file="../../common/masterbottom.jsp"%>